home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / Z4SDFILE.CPP < prev    next >
C/C++ Source or Header  |  1993-08-22  |  7KB  |  192 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    z4sdfile.cpp
  5. //   Title:    ZIP+4 Engine
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class Z4_SD_FILE.
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <z4.h>
  41.  
  42.  
  43. //----------------------------------------------------------------------------
  44. //   Description:    Default constructor
  45. //    Parameters:    state     State to get detail information for.
  46. //       Returns:    
  47. //----------------------------------------------------------------------------
  48. FN_M Z4_SD_FILE::Z4_SD_FILE(Z4_STATE state)
  49. {
  50.     Z4_SD_FILE::Initialize(CL_INIT_CLASS);
  51.     if (state != Z4_ST_INVALID)
  52.         Get(state);
  53. }
  54.  
  55.  
  56. //----------------------------------------------------------------------------
  57. //   Description:    Copy constructor
  58. //    Parameters:    rcz4_st_file        Reference to object to copy.
  59. //       Returns:    
  60. //----------------------------------------------------------------------------
  61. FN_M Z4_SD_FILE::Z4_SD_FILE(RCZ4_SD_FILE rcz4_st_file)
  62. {
  63.     Z4_SD_FILE::Initialize(CL_INIT_CLASS);
  64.     *this = rcz4_st_file;
  65. }
  66.  
  67.  
  68. //----------------------------------------------------------------------------
  69. //   Description:    Destructor
  70. //    Parameters:
  71. //       Returns:    
  72. //----------------------------------------------------------------------------
  73. FN_M Z4_SD_FILE::~Z4_SD_FILE()
  74. {
  75.     Z4_SD_FILE::Destroy(FALSE);
  76. }
  77.  
  78.  
  79. //----------------------------------------------------------------------------
  80. //   Description:    Destroy object. Free any resources used by object.
  81. //                          Normally called by destructor.
  82. //                        Should allow multiple calls from various classes.
  83. //                        A class should almost always re-init its variables when 
  84. //                        it is destroyed to prevent accidents.
  85. //    Parameters:    fDestroyAll        Destroy parents also?
  86. //                                            Default is TRUE.
  87. //       Returns:    TRUE if successful.
  88. //----------------------------------------------------------------------------
  89. BOOL FN_M Z4_SD_FILE::Destroy(BOOL fDestroyAll)
  90. {
  91.     if (pchCounties)
  92.         MemFree(pchCounties);
  93.     Z4_SD_FILE::Initialize(CL_INIT_CLASS_VARS);
  94.     if (fDestroyAll)                            // Destroy parent.
  95.         Z4_SD_FILE_PARENT::Destroy(fDestroyAll);
  96.     return TRUE;
  97. }
  98.  
  99.  
  100. //----------------------------------------------------------------------------
  101. //   Description:    Get detail information for a state.
  102. //    Parameters:    state     State to get detail information for.
  103. //       Returns:    TRUE if successful.
  104. //----------------------------------------------------------------------------
  105. BOOL FN_M Z4_SD_FILE::Get(Z4_STATE state)
  106. {
  107.     Assert(state >= Z4_ST_FIRST && state <= Z4_ST_LAST);
  108.     Destroy();                                    // Destroy current state detail info
  109.                                                     // No state info?
  110.     PCSZ pszState = Z4_ST_FILE::Abbreviation(state);
  111.     if (!DioIsLogicalFile(pszState, DFT_RANDOM))
  112.         return FALSE;
  113.     HLF hlf;                                        // Load information
  114.     if (!DioOpenLogical(pszState, &hlf, DFT_RANDOM))
  115.         return SetError();
  116.     if (!DioRead(hlf, (PBYTE)&sd, sizeof(sd), NULL))
  117.         goto ERROR_EXIT;
  118.     pchCounties = (PCHAR)MemAlloc((SIZET)sd.cbCounties);
  119.     if (pchCounties == NULL)
  120.         goto ERROR_EXIT;
  121.     if (!DioRead(hlf, (PBYTE)pchCounties, (SIZET)sd.cbCounties, NULL))
  122.         goto ERROR_EXIT;
  123.     if (!DioCloseLogical(hlf))
  124.         goto ERROR_EXIT;
  125.     fValid = TRUE;
  126.     return TRUE;
  127. ERROR_EXIT:
  128.     DioCloseLogical(hlf);
  129.     return SetError();
  130. }
  131.  
  132.  
  133. //----------------------------------------------------------------------------
  134. //   Description:    Initialize object. 
  135. //                          Normally called by constructor.
  136. //                        Should allow multiple calls from various classes.
  137. //    Parameters:    sInit        Initialization code. May be one of the following:
  138. //                                        CL_INIT_CLASS            Reset class variables and
  139. //                                                                    and dynamic allocations for
  140. //                                                                    this class only.
  141. //                                        CL_INIT_CLASS_VARS    Reset class variables for
  142. //                                                                    this class only.
  143. //                                        CL_INIT_VARS            Reset class variables for
  144. //                                                                    this class only.
  145. //                                        CL_INIT_ALL                Initialize class and all 
  146. //                                                                    parent class, including
  147. //                                                                    dynamic memory allocation.
  148. //                                    Default is CL_INIT_ALL
  149. //       Returns:    TRUE if successful.
  150. //----------------------------------------------------------------------------
  151. BOOL FN_M Z4_SD_FILE::Initialize(SHORT sInit)
  152. {
  153.     if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
  154.         Z4_SD_FILE_PARENT::Initialize(sInit);
  155.  
  156.     memset(&sd, 0, sizeof(sd));
  157.     pchCounties = NULL;
  158.     fValid = FALSE;
  159.     return TRUE;
  160. }
  161.  
  162.  
  163. //----------------------------------------------------------------------------
  164. //   Description:    Check if object is valid
  165. //                          IsValid() && IsError() MUST NOT BE DEPENDENT ON ONE ANOTHER.
  166. //    Parameters:
  167. //       Returns:    TRUE if valid
  168. //----------------------------------------------------------------------------
  169. BOOL FN_M Z4_SD_FILE::IsValid() const
  170. {
  171.     return Z4_SD_FILE_PARENT::IsValid() && fValid;
  172. }
  173.  
  174.  
  175. //----------------------------------------------------------------------------
  176. //   Description:    Assignment operator
  177. //                          NOTE: Don't copy object into self
  178. //    Parameters:    rcz4_st_file        Reference to right value.
  179. //       Returns:    Reference to new object.
  180. //----------------------------------------------------------------------------
  181. RCZ4_SD_FILE FN_M Z4_SD_FILE::operator=(RCZ4_SD_FILE rcz4_st_file)
  182. {
  183.     if (this != &rcz4_st_file)
  184.         {
  185.         Invalid("Z4_SD_FILE::operator=");
  186.         }
  187.     return (RCZ4_SD_FILE)*this;
  188. }
  189. //----------------------------------------------------------------------------
  190. //------------------------------- End of File --------------------------------
  191. //----------------------------------------------------------------------------
  192.